package edu.xidian.forum.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.xidian.forum.common.Result;
import edu.xidian.forum.dto.BillboardDto;
import edu.xidian.forum.entity.Billboard;
import edu.xidian.forum.mapper.BillboardMapper;
import edu.xidian.forum.service.BillboardService;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class BillboardServiceImpl extends ServiceImpl<BillboardMapper, Billboard> implements BillboardService {

    @Override
    public Result<Billboard> insertOne(BillboardDto billboardDto) {
        if (billboardDto.getText() == null || billboardDto.getText().equals("")) {
            return Result.failed();
        }
        Billboard billboard = new Billboard();
        billboard.setContent(billboardDto.getText());
        billboard.setCreateTime(new Date());
        billboard.setShow(true);
        try {
            baseMapper.insert(billboard);
        } catch (Exception e) {
            return Result.failed();
        }
        return Result.success(billboard);
    }

}
